package com.win.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/**
 * @Author:
 * @Date: 2024/7/19 12:53
 * @Description:
 */
public class CookieDemo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 请求字符编码
        req.setCharacterEncoding("utf-8");
        // 响应字符编码
        resp.setCharacterEncoding("utf-8");

        //创建cookie
        Cookie cookie = new Cookie("lastLongTime", System.currentTimeMillis() + "");
        //设置cookie的有效期设置为0
        cookie.setMaxAge(0);
        resp.addCookie(cookie);
    }
}
